﻿using System;
using System.Threading;
using System.Windows.Threading;

namespace XamlMvp
{
    public class DispatcherWrapper : IDispatcher
    {
        readonly Dispatcher dispatcher;

        public DispatcherWrapper(Dispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
        }

        public void BeginInvoke(Action a)
        {
            dispatcher.BeginInvoke(a);
        }

        public void BeginInvoke(Delegate d, params object[] args)
        {
            dispatcher.BeginInvoke(d, args);
        }

        public bool CheckAccess()
        {
            return dispatcher.CheckAccess();
        }

        public void BackgroundInvoke(Action<IDispatcher> a)
        {
            ThreadPool.QueueUserWorkItem((o) => a((IDispatcher)o), this);
        }
    }
}
